package com.breezelin.freshmarket.adpaters;

/**
 * Created by Breeze Lin
 * 7:01 2016/5/30
 * 1linyufeng1@gmail.com
 */

import android.content.Context;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.TextView;

import com.breezelin.freshmarket.R;
import com.breezelin.freshmarket.entities.data.Spec;

import java.util.LinkedList;

/**
 * 产品规格适配器
 */
public class SpecAdapter extends Adapter {

	/**
	 * 上下文
	 */
	private Context context;
	/**
	 * 规格
	 */
	private LinkedList<Spec> specs;

	/**
	 * @param context 上下文
	 * @param specs   规格
	 */
	public SpecAdapter(Context context, LinkedList<Spec> specs) {
		this.context = context;
		this.specs = specs;
	}

	@Override
	public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		TextView view = (TextView) LayoutInflater.from(context)
				.inflate(R.layout.item_spec, parent, false);
		return new ViewHolder(view) {
		};
	}

	@Override
	public void onBindViewHolder(ViewHolder holder, int position) {
		((TextView) holder.itemView).setText(specs.get(position).getSpec());
	}

	@Override
	public int getItemCount() {
		return specs.size();
	}
}
